package com.lyt.springboot.util.algorithm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class S20 {
    public int[] FindNumsAppearOnce (int[] nums) {
//        int[] arr = new int[0];
//        if(nums == null && nums.length==0) {
//            return arr;
//        }
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(!map.containsKey(nums[i])) {
                map.put(nums[i],1);
            }else {
                map.put(nums[i],map.get(nums[i])+1);
            }
        }
        ArrayList<Integer> list = new ArrayList<>();
        for(Integer key:map.keySet()) {
            if(map.get(key) == 1) {
                list.add(key);
            }
        }
        int[] arr1 = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            arr1[i]  = list.get(i);
        }
        Arrays.sort(arr1);
        return arr1;
    }


    public int minNumberDisappeared (int[] nums) {
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],1);
        }
        for (int i = 1; i < nums.length+1; i++) {
            if(map.containsKey(i)){
                return i;
            }
        }
        return nums.length+1;

    }



    public static void main(String[] args) {
        int[] arr = {7,8,9};
        S20 s20 = new S20();
        s20.minNumberDisappeared(arr);
    }
}
